﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Win32;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Collections;
using System.Drawing;

public partial class Controls_PersonInformation : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void SetPerson(int mid)
    {
        DBaccess db = new DBaccess();
        DataSet ds = new DataSet();
        string sql = "select mname,dname,gpa,score, logo from mr_member a,mr_student b,mr_department c where a.mid = b.sid and b.department=c.did and mid='" + mid.ToString() + "'";
        ds = db.GetDataSet(sql);
        LabelMid.Text = mid.ToString();
        Image1.ImageUrl = ResolveUrl(ds.Tables[0].Rows[0]["logo"].ToString());
        LabelMname.Text += ds.Tables[0].Rows[0]["mname"].ToString();
        LabelDepart.Text += ds.Tables[0].Rows[0]["dname"].ToString();
        LabelGPA.Text = ds.Tables[0].Rows[0]["gpa"].ToString();
        LabelScore.Text = ds.Tables[0].Rows[0]["score"].ToString();
        
        ds = db.GetDataSet("select value from mr_parameter where pname='sim'");
        MyVector mvall = new MyVector(mid);
        MyVector mvreco = new MyVector();
        MyVector mvnoreco = new MyVector();
        mvall.Recommand(double.Parse(ds.Tables[0].Rows[0][0].ToString()));
        mvall.Sort();
        mvreco = mvall.GetRecommand();
        mvnoreco = mvall.GetNoRecommand();
        int i;
        for (i = 0; i < mvnoreco.GetLength(); i++)
        {
            Label lab = new Label();
            lab.Width = 195;
            if (i % 4 == 2 || i % 4 == 3) lab.BackColor = Color.FromArgb(255, 255, 150);
            lab.Text = mvnoreco.GetIname(i) + ":" + mvnoreco.GetValue(i).ToString("0.00");
            Panel2.Controls.Add(lab);
        }
        for (i = 0; i < mvreco.GetLength(); i++)
        {
            LinkButton lb = new LinkButton();
            lb.Width = 195;
            if (i % 4 == 2 || i % 4 == 3) lb.BackColor = Color.FromArgb(255, 255, 150);
            lb.Text = mvreco.GetIname(i) + ":" + mvreco.GetValue(i).ToString("0.00");
            lb.CommandArgument = mvreco.GetIname(i);
            lb.Command += new CommandEventHandler(this.lb_Click);
            Panel3.Controls.Add(lb);
        }
        if (mvnoreco.GetLength() == 0)
        {
            Label lab = new Label();
            lab.Width = 195;
            lab.Text = "无已评分的课程";
            Panel2.Controls.Add(lab);
        }
        if (mvreco.GetLength() == 0)
        {
            Label lab = new Label();
            lab.Width = 195;
            lab.Text = "所有课程都已评分";
            Panel3.Controls.Add(lab);
        }
    }

    public void lb_Click(object sender, CommandEventArgs e)
    {
        Response.Write("test");
        DBaccess db = new DBaccess();
        DataSet ds = new DataSet();
        String cname = e.CommandArgument.ToString();
        LabelDestCourse.Text = cname;
        LabelDestCourse.Visible = true;
        int mid = int.Parse(LabelMid.Text);
        SetPerson(mid);
        ds = db.GetDataSet("select cid from mr_course where cname = '" + cname + "'");
        int cid = int.Parse(ds.Tables[0].Rows[0][0].ToString());
        ds = db.GetDataSet("select * from mr_v_recommand where " + cid + " is not null");
        GridView1.DataSource = ds;
        GridView1.DataBind();
        GridView1.Visible = true;
        //LabelStep1.Text = 
    }
}